package com.software.cool.api.app.v1.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author admin
 * @date 2019/5/25
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppV1Result <T>{

	@ApiModelProperty(value="成功|失败",name="success",example="true|false")
	private boolean success;
	@ApiModelProperty(value="错误信息",name="errMsg",example="账号不存在")
	private String errMsg;

	private Integer count;

	@ApiModelProperty(value="数据",name="data",example="string|map|object|list")
	private T data;

	/**
	 * 默认返回成功
	 * @param result 返回成功时的数据
	 * @return 返回对应成功的CommonReturnType实体, data字段通过参数指定
	 */
	public static <T> AppV1Result success(T result,Integer count){
		AppV1Result<T> type = new AppV1Result<>();
		type.setSuccess(true);
		type.setErrMsg(null);
		type.setCount(count);
		type.setData(result);
		return type;
	}

	/**
	 * 默认返回成功， 不带任何数据
	 * @param <T>
	 * @return
	 */
	public static <T> AppV1Result success(){
		return AppV1Result.success(null,0);
	}

	
	public static AppV1Result fail(String errMsg) {
		AppV1Result type = new AppV1Result();
		type.setSuccess(false);
		type.setErrMsg(errMsg);
		return type;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
